package gui;

import java.util.LinkedList;

import javax.swing.table.AbstractTableModel;

import ordersList.MyOrdersList;
import ordersList.OrderList;
import ordersList.OrdersManager;
import ordersList.PublicOrdersList;

public class TableModel extends AbstractTableModel {

	// Atributos
	private int columnsCount;
	private OrderList orderList;

	// Construtor
	public TableModel(OrdersManager ordersManager, OrderList.Type orderListType) {
		this.columnsCount = 4;
		if (orderListType == OrderList.Type.MY_ORDER_LIST)
			orderList = ordersManager.getMyOrdersList();
		else if(orderListType == OrderList.Type.PUBLIC_ORDER_LIST)
			orderList = ordersManager.getPublicOrdersList();

	}

	// MŽtodos
	@Override
	public int getColumnCount() {
		return this.columnsCount;
	}

	@Override
	public int getRowCount() {
		return orderList.getLength();
	}

	@Override
	public Object getValueAt(int row, int col) {
		switch (col) {
		case 0:
			return orderList.getOrder(row).getNickname();
		case 1:
			return orderList.getOrder(row).getStock();
		case 2:
			return orderList.getOrder(row).getNumberOfUnits();
		case 3:
			return orderList.getOrder(row).getPricePerUnit();
		}
		return null;
	}

	@Override
	public String getColumnName(int column) {
		switch (column) {
		case 0:
			return "Nickname";
		case 1:
			return "Nome Ac�‹o";
		case 2:
			return "Quantidade";
		case 3:
			return "Pre�o";
		}
		return null;
	}

	public void addBuyOrder() {
		orderList.getOrder(0);
		fireTableDataChanged();
	}

}
